# Contributor: Alex McGrath <amk@amk.ie>
# Maintainer: Alex McGrath <amk@amk.ie>
pkgname=gotosocial
pkgver=0.13.0
pkgrel=0
pkgdesc="An ActivityPub social network server"
url="https://github.com/superseriousbusiness/gotosocial"
arch="all"
license="AGPL-3.0-only"
install="$pkgname.pre-install"
pkgusers="gotosocial"
pkggroups="gotosocial"
makedepends="go yarn nodejs"
subpackages="$pkgname-openrc"
source="https://github.com/superseriousbusiness/gotosocial/releases/download/v$pkgver/gotosocial-$pkgver-source-code.tar.gz
	gotosocial.initd
	10-config.patch
	"
builddir="$srcdir"

options="!check" # lots of flakey tests

case "$CARCH" in
	# flaky test
	s390x) options="!check";;
esac

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	yarn --cwd ./web/source install
	yarn --cwd ./web/source ts-patch install
	yarn --cwd ./web/source build
	go build -o gotosocial ./cmd/gotosocial
}

check() {
	# skip tests in internal/media as they're failing
	local pkgs="$(go list ./... | grep -v 'internal/media')"
	CGO_ENABLED=0 GTS_DB_TYPE="sqlite" GTS_DB_ADDRESS=":memory:" \
		go test $pkgs
}

package() {
	install -Dm755 "$srcdir"/gotosocial.initd \
		"$pkgdir"/etc/init.d/gotosocial
	install -Dm755 "$builddir"/gotosocial \
		-t "$pkgdir"/usr/bin/

	install -d -o gotosocial -g gotosocial "$pkgdir"/etc/gotosocial
	install -Dm640 "$builddir"/example/config.yaml "$pkgdir"/etc/gotosocial/gotosocial.yml

	mkdir -p "$pkgdir"/usr/share/webapps/gotosocial
	cp -r "$builddir"/web/assets "$pkgdir"/usr/share/webapps/gotosocial
	cp -r "$builddir"/web/template "$pkgdir"/usr/share/webapps/gotosocial

	install -d -o gotosocial -g gotosocial "$pkgdir"/var/lib/gotosocial
}

sha512sums="
0d24a55caf029cbe8a883651179d5c2485ad08c2755a56f8e009e5fe62ca1c42453a1156ffcca893216f5ad570430fdde9bc9b3d2d4d64ac893e1b767bfdf773  gotosocial-0.13.0-source-code.tar.gz
f9e4aa4177d727c5a2822e292a54b1d488c60c1f2f62fc64d193e3de6c1168ae74c6273eaed86f148cf0390505903bcf19b97f375d7f2838a892275abd79d9d6  gotosocial.initd
e1030586395c7bcca2bf348f764bb51de75e503a29c163e95f155b2192e213db61376f0b15e957813be917ba7f5d28abc8c4e944971ea6db64088424add97874  10-config.patch
"
